<?php
declare (strict_types = 1);

namespace app\api\model;
use think\model\concern\SoftDelete;
/**
 * 代办事项模型
 */
class TodoList extends Base
{
    use SoftDelete;
    protected $deleteTime = 'delete_time';
    protected $autoWriteTimestamp = 'datetime';

    /**
     * 获取所有代办事项
     */
    public static function getTodoList($id,$job)
    {
        $data = TodoList::where(
            [
                'user_id' => $id,
                'job'  => $job
            ]
        )->field('id,title,status')->order('id','desc')->select()->toArray();
        return [
            'code' => 200,
            'message' => '获取数据成功',
            'data' => $data
        ];
    }

    /**
     * 
     * 删除代办事项
     */
    public static function delTodoList($id)
    {
        $memo = TodoList::find($id);
        if(empty($memo)){
            return [];
        }
        $success = $memo->delete() === true ? true : [];
        return $success;
    }

    /**
     * 
     * 新增事项
     */

    public static function addTodoList($data)
    {
        $success = TodoList::create($data);
        return $success;
    }

    /**
     * 
     * 修改事项状态
     */
    public static function editTodoList($id,$status)
    {
        $todo = TodoList::find($id);
        if(empty($todo)){
            return [];
        }
        $status = $status == 0 ? 1 :0;
        $todo->status = $status;
        $success = $todo->save() === true ? true : [];
        return $success;
    }
}